﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Windows.Forms;

namespace BHair
{
    public partial class Frmgysadd : Form
    {
        public Frmgysadd()
        {
            InitializeComponent();
        }

        private void Frmgysadd_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string id = this.txtgysid.Text;
            string name = this.txtgysname.Text;
            string phone = this.txtgysphone.Text;
            string address = this.txtaddress.Text;
            string bz = this.txtbz.Text;
            string lxr = this.txtgyslxr.Text;
            string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
            SqlConnection sqlconn = new SqlConnection(constr);
            //定义新增语句
            string addsql = string.Format("INSERT INTO [BHairDB].[dbo].[gys]"
                + "([gysID]"
                + ",[gysname]"
                + ",[gysaddress]"
                + ",[gysphone]"
                + ",[gysbz]"
                + ",[gyslxr])"
                + "VALUES"
                +"({0},'{1}','{2}','{3}','{4}','{5}')",id,name,address,phone,bz,lxr);
            try
            {
                sqlconn.Open();
                SqlCommand comm = new SqlCommand(addsql,sqlconn);
                comm.ExecuteNonQuery();
                MessageBox.Show("添加成功");
                sqlconn.Close();
            }
            catch(Exception ex) 
            {
                MessageBox.Show(ex.Message);
                sqlconn.Close();
            }


        }
    }
}
